home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
oper_sys
/
quartz
/
quartz10.lha
/
src
/
runtime
/
internal.h
< prev
next >
Wrap
C/C++ Source or Header
|
1990-04-29
|
3KB
|
130 lines
/* Internal data structures needed by the thread package */
#define ThreadsPerBunch 20
#define ThreadThreshold (ThreadsPerBunch*2)
typedef struct ready_queue {
SpinLock lock;
Thread *started;
SynchProfile *empty;
} ReadyQ;
/* shared info per processor: only for profiling, for now */
typedef struct processor {
Thread *curThread; /* DONT MOVE */
SynchProfile *synchList; /* the synch obj's I created */
SpinLock profLock;
int numSamples;
usclk_t lastSample;
Thread idleThread;
IdStackEntry idStack[InitIdStackSize];
} Processor;
/* private information per processor not accessed by anyone else */
typedef struct private_proc {
int *sp; /* DONT MOVE -- see startup() */
int *ebp; /* DONT MOVE -- see startup() */
int seed;
Thread *thread; /* DONT MOVE */
Processor *proc;
Thread *idleThread;
int myId;
ReadyQ *lastLook;
ReadyQ *putQ;
SynchProfile *freeSynch; /* free list of synch objects */
Thread *deadThreads;
/* not used if I'm profiling */
int deadCount;
Thread *deadMiddle; /* valid only if count > ThreadsPerBunch */
} PrivateProcessor;
extern private PrivateProcessor pP;
extern shared Processor processorList[];
extern int processGroup;
extern int affinity;
void ThreadpoolInit(), ThreadpoolGet(), ThreadpoolPut();
Stack *StackpoolGet();
void StackpoolPut(), StackpoolInit(), KillAll();
void MFork(), ProcessorListInit(), PrivProcessorInit();
/* A few nasty macros -- called from a bunch of places, and too
frequently to set off in a function call */
#define ThreadAlloc(t) { \
pP.deadCount--; \
if (!(t = pP.deadThreads)) {\
ThreadpoolGet(); \
t = pP.deadThreads;\
}\
pP.deadThreads = t->next;\
}
#define ThreadPut(t,l) ((t)->next = *(l), *(l) = (t))
#define TF(t) { \
ThreadPut(t, &pP.deadThreads); \
if (++pP.deadCount == (ThreadsPerBunch + 1)) \
pP.deadMiddle = pP.deadThreads; \
else if (pP.deadCount == ThreadThreshold) \
ThreadpoolPut(); \
}
#ifdef PROFILE
#define ReadyQPut(t) { \
AddNominal(); \
TSetStateReady(t); \
SpinLockAcquire(&(pP.putQ->lock)); \
ThreadPut(t, &(pP.putQ->started)); \
SpinLockRelease(&(pP.putQ->lock)); \
}
#define ThreadFree(t) { \
if ((t)->p) t->p->status = DISCARDED; \
else { TF(t); } \
}
#define Block(l) MY_BLOCK(l)
#define BlockNoProf(l) (SetStateBlocked(), NP_BLOCK(l))
#else
#define ReadyQPut(t) { \
SpinLockAcquire(&(pP.putQ->lock)); \
ThreadPut(t, &(pP.putQ->started)); \
SpinLockRelease(&(pP.putQ->lock)); \
}
#define ThreadFree(t) TF(t)
#define Block(l) NP_BLOCK(l)
#define BlockNoProf(l) NP_BLOCK(l)
#endif
#define MyShmalloc(type,n) (type *)myshmalloc((unsigned)(sizeof(type) * (n)))
void TooSmall();
char *shmalloc(), *myshmalloc();
#ifdef DEBUG
#define ASSERT(c) if (!(c)) { printf("FAILED: %s\n","c"); abort();} else
#else
#define ASSERT(c)
#endif
#define SpinLockType 0x12345678
#define SynchProfileType 0x23456789
#define ChildDataType 0x3456789a
#define ConcurrentDataType 0x456789ab
#define StackType 0x56789abc
#define ThreadType 0x6789abcd
#define BarrierType 0x789abcde
#define LockType 0x89abcdef
#define ConditionType 0x9abcdef1